import axios from 'axios'
import { Message } from 'element-ui'

axios.defaults.timeout = 60000

axios.interceptors.request.use(config => {
  return config
}, err => {
  return Promise.resolve(err)
})

axios.interceptors.response.use(data => {
  return data
}, err => {
  if (err.response) {
    if (err.response.status === 401) {
      Message.error(err.response.data.msg)
    } else {
      Message.error({message: err.message})
    }
  } else {
    if (err.message.includes('timeout')) {
      Message.error({message: 'Request Time Out'})
    } else {
      Message.error({message: err.message})
    }
  }
  return Promise.resolve({data: err})
})
